﻿#include "../../x/draw/draw.h"
#include "../../ctlHelp.h"

Status GdiPlusAddRoundRect(GraphicsPath& path, INT x, INT y, INT cx, INT cy, INT d)
{
	d *=2;
	if(d < 2) return path.AddRectangle(Rect(x, y, cx, cy));
	if(d > swui::ctlMin(cx, cy)) d = swui::ctlMin(cx, cy);
	GraphicsPath p;
	p.AddArc(x, y, d, d, 180, 90);
	p.AddArc(x + cx - d, y, d, d, 270, 90);
	p.AddArc(x + cx - d, y + cy - d, d, d, 0, 90);
	p.AddArc(x, y + cy - d, d, d, 90, 90);
	p.CloseFigure();
	return path.AddPath( & p, FALSE);
}
Status GdiPlusAddRoundRect(GraphicsPath& path, INT x, INT y, INT cx, INT cy, INT d, INT w)
{
	d *=2;
	if(d < 2) return path.AddRectangle(Rect(x, y, cx, cy));
	if(d > swui::ctlMin(cx, cy)) d = swui::ctlMin(cx, cy);
	GraphicsPath p;
	if(w & 1) p.AddArc(x, y, d, d, 180, 90);
	else p.AddLine(x, y, x + cx - d, y);
	if(w & 2) p.AddArc(x + cx - d, y, d, d, 270, 90);
	else p.AddLine(x + cx, y, x + cx, y + cy - d);
	if(w & 4) p.AddArc(x + cx - d, y + cy - d, d, d, 0, 90);
	else p.AddLine(x + cx, y + cy, x + d, y + cy);
	if(w & 8) p.AddArc(x, y + cy - d, d, d, 90, 90);
	else p.AddLine(x, y + cy, x, y + d);
	p.CloseFigure();
	return path.AddPath( & p, FALSE);
}
Status GdiPlusDrawRoundRect(Graphics& graphics, Pen*pen, INT x, INT y, INT cx, INT cy, INT d)
{
	GraphicsPath p;
	GdiPlusAddRoundRect(p, x, y, cx, cy, d);
	return graphics.DrawPath(pen,  & p);
}
Status GdiPlusFillRoundRect(Graphics& graphics, Brush*brush, INT x, INT y, INT cx, INT cy, INT d)
{
	GraphicsPath p;
	GdiPlusAddRoundRect(p, x, y, cx, cy, d);
	return graphics.FillPath(brush,  & p);
}
Status GdiPlusDrawRoundRect(Graphics& graphics, Pen*pen, INT x, INT y, INT cx, INT cy, INT d, INT w)
{
	GraphicsPath p;
	GdiPlusAddRoundRect(p, x, y, cx, cy, d, w);
	return graphics.DrawPath(pen,  & p);
}
Status GdiPlusFillRoundRect(Graphics& graphics, Brush*brush, INT x, INT y, INT cx, INT cy, INT d, INT w)
{
	GraphicsPath p;
	GdiPlusAddRoundRect(p, x, y, cx, cy, d, w);
	return graphics.FillPath(brush,  & p);
}